[XEND][XM] Fix bug in XendDomainInfo.recreate introduced by refactoring.
authorAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 17:24:18 +0000 (18:24 +0100)
committerAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 17:24:18 +0000 (18:24 +0100)
* Replaced autostart and autostop with more descriptive on_xend_start
  and on_xend_stop for the configuration.

Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xend/XendConfig.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py

index 6506e6abc9ab9f12dda5e64e62c90c4591cbbf62..1dab6886d8368f7ff119824149f291e48ca384e7 100644 (file)
@@ -124,12 +124,11 @@ XENAPI_UNSUPPORTED_IN_LEGACY_CFG = [
 
 # All parameters of VMs that may be configured on-the-fly, or at start-up.
 VM_CONFIG_ENTRIES = [
-    ('autostart',  int),
-    ('autostop',   int),    
     ('name',        str),
     ('on_crash',    str),
     ('on_poweroff', str),
     ('on_reboot',   str),
+    ('on_xend_start', str),
     ('on_xend_stop', str),        
 ]
 
@@ -216,9 +215,8 @@ DEFAULT_CONFIGURATION = (
     ('device',       lambda info: {}),
     ('image',        lambda info: None),
     ('security',     lambda info: []),
-    ('autostart',    lambda info: 0),
-    ('autostop',     lambda info: 0),
-    ('on_xend_stop', lambda info: 'shutdown'),
+    ('on_xend_start', lambda info: 'ignore'),    
+    ('on_xend_stop', lambda info: 'ignore'),
 
     ('cpus',         lambda info: []),
     ('cpu_weight',   lambda info: 1.0),
@@ -469,7 +467,7 @@ class XendConfig(dict):
             dev_info = {}
             for opt, val in config[1:]:
                 dev_info[opt] = val
-
+            log.debug("XendConfig: reading device: %s" % dev_info)
             # create uuid if it doesn't
             dev_uuid = dev_info.get('uuid', uuid.createString())
             dev_info['uuid'] = dev_uuid
@@ -654,9 +652,8 @@ class XendConfig(dict):
             sxpr.append(['up_time', str(uptime)])
             sxpr.append(['start_time', str(self['start_time'])])
 
-        sxpr.append(['autostart', self.get('autostart', 0)])
-        sxpr.append(['autostop', self.get('autostop', 0)])
-        sxpr.append(['on_xend_stop', self.get('on_xend_stop', 'shutdown')])
+        sxpr.append(['on_xend_start', self.get('on_xend_start', 'ignore')])
+        sxpr.append(['on_xend_stop', self.get('on_xend_stop', 'ignore')])
 
         sxpr.append(['status', domain.state])
 
@@ -729,6 +726,8 @@ class XendConfig(dict):
             raise XendConfigError("XendConfig: device_add requires some "
                                   "config.")
 
+        log.debug("XendConfig.device_add: %s" % str(cfg_sxp))
+
         if cfg_sxp:
             config = sxp.child0(cfg_sxp)
             dev_type = sxp.name(config)
@@ -738,7 +737,6 @@ class XendConfig(dict):
                 for opt, val in config[1:]:
                     dev_info[opt] = val
             except ValueError:
-                log.debug('XendConfig.device_add: %s' % config)
                 pass # SXP has no options for this device
 
             # create uuid if it doesn't exist
index 8b650307aa3f09f56b6c5d7fabb3f18a78f0bcd7..bbb5192bca21b92665dfb6be89741f52abb99ad9 100644 (file)
@@ -523,8 +523,7 @@ class XendDomain:
                     continue
                 
                 if dom.state == XendDomainInfo.DOM_STATE_RUNNING:
-                    shouldShutdown = dom.info.get('autostop', 0)
-                    shutdownAction = dom.info.get('on_xend_stop', 'shutdown')
+                    shutdownAction = dom.info.get('on_xend_stop', 'ignore')
                     if shouldShutdown and shutdownAction == 'shutdown':
                         log.debug('Shutting down domain: %s' % dom.getName())
                         dom.shutdown("poweroff")
index c8907bdb3fa2cfb1aacb446f765fe9c945e97071..6a362fecf36a95c5556662f1403b5d3ccbbdd465 100644 (file)
@@ -102,8 +102,7 @@ VM_STORE_ENTRIES = [
     ('shadow_memory', int),
     ('maxmem',        int),
     ('start_time',    float),
-    ('autostart',  int),
-    ('autostop',   int),
+    ('on_xend_start', str),
     ('on_xend_stop', str),
     ]
 
@@ -194,23 +193,28 @@ def recreate(info, priv):
     #       entry disappears (eg. xenstore-rm /)
     #
     if domid != 0:
-        vmpath = xstransact.Read(dompath, "vm")
-        if not vmpath:
-            log.warn('/dom/%d/vm is missing. recreate is confused, trying '
-                     'our best to recover' % domid)
-            needs_reinitialising = True
-        
-        uuid2_str = xstransact.Read(vmpath, "uuid")
-        if not uuid2_str:
-            log.warn('%s/uuid/ is missing. recreate is confused, trying '
-                     'our best to recover' % vmpath)
-            needs_reinitialising = True
-
-        uuid2 = uuid.fromString(uuid2_str)
-        if uuid1 != uuid2:
-            log.warn('UUID in /vm does not match the UUID in /dom/%d.'
-                     'Trying out best to recover' % domid)
-            needs_reinitialising = True
+        try:
+            vmpath = xstransact.Read(dompath, "vm")
+            if not vmpath:
+                log.warn('/dom/%d/vm is missing. recreate is confused, '
+                         'trying our best to recover' % domid)
+                needs_reinitialising = True
+                raise XendError('reinit')
+            
+            uuid2_str = xstransact.Read(vmpath, "uuid")
+            if not uuid2_str:
+                log.warn('%s/uuid/ is missing. recreate is confused, '
+                         'trying our best to recover' % vmpath)
+                needs_reinitialising = True
+                raise XendError('reinit')
+
+            uuid2 = uuid.fromString(uuid2_str)
+            if uuid1 != uuid2:
+                log.warn('UUID in /vm does not match the UUID in /dom/%d.'
+                         'Trying out best to recover' % domid)
+                needs_reinitialising = True
+        except XendError:
+            pass # our best shot at 'goto' in python :)
 
     vm = XendDomainInfo(xeninfo, domid, dompath, augment = True, priv = priv)
     
@@ -263,7 +267,6 @@ def createDormant(xeninfo):
     
     # Remove domid and uuid do not make sense for non-running domains.
     xeninfo.pop('domid', None)
-    xeninfo.pop('uuid', None)
     vm = XendDomainInfo(XendConfig(cfg = xeninfo))
     return vm    
 
@@ -506,10 +509,11 @@ class XendDomainInfo:
         @param dev_config: device configuration
         @type  dev_config: dictionary (parsed config)
         """
+        log.debug("XendDomainInfo.device_create: %s" % dev_config)
         dev_type = sxp.name(dev_config)
         devid = self._createDevice(dev_type, dev_config)
+        self.info.device_add(dev_type, cfg_sxp = dev_config)        
         self._waitForDevice(dev_type, devid)
-        self.info.device_add(dev_type, cfg_sxp = dev_config)
         return self.getDeviceController(dev_type).sxpr(devid)
 
     def device_configure(self, dev_config, devid):
@@ -622,7 +626,7 @@ class XendDomainInfo:
 
         if not self.info['device'] and devices is not None:
             for device in devices:
-                self.info.device_add(device[0], cfg_sxp = device[1])
+                self.info.device_add(device[0], cfg_sxp = device)
 
     #
     # Function to update xenstore /vm/*
index 21cb03817e7c4c7a16f688b9ea73b9ce18916324..e6e60dc4a61565ae5ac2b56ad86798ef5d914a88 100644 (file)
@@ -439,17 +439,14 @@ gopts.var('uuid', val='',
           addresses for virtual network interfaces.  This must be a unique 
           value across the entire cluster.""")
 
-gopts.var('autostart', val='no|yes',
-          fn=set_bool, default=0,
-          use="Should the start VM automatically when Xend starts.")
-
-gopts.var('autostop', val='no|yes',
-          fn=set_bool, default=0,
-          use="Should stop VM automatically when Xend stops.")
-
-gopts.var('on_xend_stop', val='shtudown|suspend',
-          fn=set_value, default="shutdown",
-          use="""Behaviour when Xend stops and autostop is on:
+gopts.var('on_xend_start', val='ignore|start',
+          fn=set_value, default='ignore',
+          use='Action to perform when xend starts')
+
+gopts.var('on_xend_stop', val='continue|shutdown|suspend',
+          fn=set_value, default="ignore",
+          use="""Behaviour when Xend stops:
+          - ignore:         Domain continues to run;
           - shutdown:       Domain is shutdown;
           - suspend:        Domain is suspended;
           """)
@@ -685,7 +682,7 @@ def make_config(vals):
     map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory',
                    'restart', 'on_poweroff',
                    'on_reboot', 'on_crash', 'vcpus', 'features',
-                   'autostart', 'autostop', 'on_xend_stop'])
+                   'on_xend_start', 'on_xend_stop'])
 
     if vals.uuid is not None:
         config.append(['uuid', vals.uuid])